﻿using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using InTheHand.Net;
using InTheHand.Net.Sockets;
using InTheHand.Net.Bluetooth;

namespace Cockcrow
{
    public partial class BTConnect : Form
    {
        private ChatMainForm frm;
        private BluetoothClient bluetoothClient;
        BluetoothDeviceInfo[] bluetoothDeviceInfo;
        public BTConnect(ChatMainForm frm) { InitializeComponent(); this.frm = frm; }
        private void SearchDev(object sender, EventArgs e)
        {
            BluetoothRadio.PrimaryRadio.Mode = RadioMode.Discoverable;          //블루투스 모드를 Discoverable 모드로 전환 
            bluetoothClient = new BluetoothClient();
            Cursor.Current = Cursors.WaitCursor;                                //검색하는 동안 기다리는 커서로 변경 
            bluetoothDeviceInfo = bluetoothClient.DiscoverDevices(10);          //찾을 최대의 디바이스 수 
            BTList.DataSource = bluetoothDeviceInfo;                            // 찾은 디바이스 이름과 주소를 콤보박스에 명시  
            BTList.DisplayMember = "DeviceName";
            BTList.ValueMember = "DeviceAddress";
            BTList.Focus();
            Cursor.Current = Cursors.Default;                                   //커서를 원래대로 
        }
        private void SetBluetoothAdd() { frm.SetBlutoothClient((BluetoothAddress)BTList.SelectedValue, bluetoothClient); }
        private void ConnectDev(object sender, EventArgs e) { SetBluetoothAdd(); this.Close(); }//frm.ConnectBluetooth(); }
        private void BTCCancel(object sender, EventArgs e) { this.Close(); }
        public void BTCClose() { bluetoothClient.Close(); }
    }
}